package com.guomei.mapper.curse;

import org.apache.ibatis.annotations.Param;

import com.guomei.bean.exam.domain.ExamAnswerDetail;
import com.guomei.bean.exam.domain.ExamUserAnswerVO;

import java.util.List;

/**
 * 考试答卷详情Mapper接口
 */
public interface ExamAnswerDetailMapper {
    
    /**
     * 根据ID查询
     */
    ExamAnswerDetail selectById(@Param("id") Long id);
    
    /**
     * 查询所有
     */
    List<ExamAnswerDetail> selectAll();
    
    /**
     * 条件查询
     */
    List<ExamAnswerDetail> selectByCondition(ExamAnswerDetail examAnswerDetail);
    
    /**
     * 新增
     */
    int insert(ExamAnswerDetail examAnswerDetail);
    
    /**
     * 批量新增
     */
    int batchInsert(List<ExamAnswerDetail> examAnswerDetails);
    
    /**
     * 根据ID更新
     */
    int updateById(ExamAnswerDetail examAnswerDetail);
    
    /**
     * 根据ID删除
     */
    int deleteById(@Param("id") Long id);
    
    /**
     * 批量删除
     */
    int batchDelete(@Param("ids") List<Long> ids);
    
    /**
     * 根据答卷ID查询
     */
    List<ExamAnswerDetail> selectByAnswerId(@Param("answerId") Long answerId);
    
    /**
     * 根据题目ID查询
     */
    List<ExamAnswerDetail> selectByQuestionId(@Param("questionId") Long questionId);
    
    /**
     * 根据答卷ID和题目ID查询
     */
    ExamAnswerDetail selectByAnswerIdAndQuestionId(@Param("answerId") Long answerId, @Param("questionId") Long questionId);
    
    /**
     * 根据答卷ID删除
     */
    int deleteByAnswerId(@Param("answerId") Long answerId);
    
    /**
     * 根据题目ID删除
     */
    int deleteByQuestionId(@Param("questionId") Long questionId);
    
    /**
     * 统计答卷详情数量
     */
    int countByAnswerId(@Param("answerId") Long answerId);
    
    /**
     * 统计题目答题数量
     */
    int countByQuestionId(@Param("questionId") Long questionId);
    
    /**
     * 计算答卷总分
     */
    Integer sumScoreByAnswerId(@Param("answerId") Long answerId);

    /**
     * 关联题目和用户回答：按答卷ID
     */
    List<ExamUserAnswerVO> selectUserAnswersByAnswerId(@Param("answerId") Long answerId);

    /**
     * 关联题目和用户回答：按考试ID和用户ID
     */
    List<ExamUserAnswerVO> selectUserAnswersByExamIdAndUserId(@Param("examId") Long examId, @Param("userId") Long userId);

    /**
     * 统计客观题总分（题型1）
     */
    Integer sumObjectiveScoreByAnswerId(@Param("answerId") Long answerId);

    /**
     * 统计主观题总分（题型2）
     */
    Integer sumSubjectiveScoreByAnswerId(@Param("answerId") Long answerId);
}
